<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: global_config.php 48 2013-09-21 11:56:45Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 48 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:56:45 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require('includes/application_top.php');

if(isset($_GET['action']) && $_GET['action'] == 'save') {

	function setValue($val = '') {
		return (!empty($val) ? '1' : '0');
	}
	
	function saveConfigVal($name) {
		global $db;
		
		$db->db_query("UPDATE
							".TABLE_CONFIGURATION."
						SET
							configuration_value = '".setValue($_POST[$name])."'
						WHERE
							configuration_key = '".$name."'");
	}
	
	function saveConfig($name) {
		global $db;
		
		$db->db_query("UPDATE
							".TABLE_CONFIGURATION."
						SET
							configuration_value = '".$_POST[$name]."'
						WHERE
							configuration_key = '".$name."'");
	}
	
	$post = $_POST['value'];

	foreach($post AS $name) {		
		if($name == 'GLOBAL_COLUMN_TOP') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_col_top = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CATEGORIES." SET categories_col_top = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_col_top = '".setValue($_POST[$name])."'");
			saveConfigVal($name);

		} elseif ($name == 'GLOBAL_COLUMN_RIGHT') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_col_right = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CATEGORIES." SET categories_col_right = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_col_right = '".setValue($_POST[$name])."'");
			saveConfigVal($name);

		} elseif ($name == 'GLOBAL_COLUMN_BOTTOM') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_col_bottom = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CATEGORIES." SET categories_col_bottom = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_col_bottom = '".setValue($_POST[$name])."'");
			saveConfigVal($name);

		} elseif ($name == 'GLOBAL_COLUMN_LEFT') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_col_left = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CATEGORIES." SET categories_col_left = '".setValue($_POST[$name])."'");
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_col_left = '".setValue($_POST[$name])."'");
			saveConfigVal($name);

		} elseif ($name == 'GLOBAL_CONTENT_SHOW_PDF_BUTTON') {
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_show_pdf = '".setValue($_POST[$name])."'");
			saveConfigVal($name);
			
		} elseif ($name == 'GLOBAL_CONTENT_SHOW_PRINT_BUTTON') {
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_show_print = '".setValue($_POST[$name])."'");
			saveConfigVal($name);
			
		} elseif ($name == 'GLOBAL_CONTENT_SHOW_BACK_BUTTON') {
			$db->db_query("UPDATE ".TABLE_CONTENT_MANAGER." SET content_show_back = '".setValue($_POST[$name])."'");
			saveConfigVal($name);
				
		} elseif($name == 'GLOBAL_PRODUCTS_SITE') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_info = '".$_POST[$name]."'");
			saveConfig($name);
			
		} elseif($name == 'GLOBAL_PRODUCTS_TELL') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_tell_a_friend = '".$_POST[$name]."'");
			saveConfig($name);
			
		} elseif($name == 'GLOBAL_PRODUCTS_ASK') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_ask_to_product = '".$_POST[$name]."'");
			saveConfig($name);

		} elseif($name == 'GLOBAL_PRODUCTS_OVERLAY') {
			$db->db_query("UPDATE ".TABLE_PRODUCTS." SET products_list_overlay = '".$_POST[$name]."'");
			saveConfig($name);
			
		} elseif($name == 'GLOBAL_EMAIL_ADDRESS') {
			$db->db_query("UPDATE ".TABLE_EMAILS." SET email_address = '".$_POST[$name]."'");
			saveConfig($name);
		
		} elseif($name == 'GLOBAL_EMAIL_ADDRESS_NAME') {
			$db->db_query("UPDATE ".TABLE_EMAILS." SET email_address_name = '".$_POST[$name]."'");
			saveConfig($name);
		
		} elseif($name == 'GLOBAL_EMAIL_REPLAY_ADDRESS') {
			$db->db_query("UPDATE ".TABLE_EMAILS." SET email_replay_address = '".$_POST[$name]."'");
			saveConfig($name);
			
		} elseif($name == 'GLOBAL_EMAIL_REPLAY_ADDRESS_NAME') {
			$db->db_query("UPDATE ".TABLE_EMAILS." SET email_replay_address_name = '".$_POST[$name]."'");
			saveConfig($name);
		} 
	}

	$message_stack->add_session('Die Werte wurden gespeichert.', 'success');
	redirect(href_link('global_config.php'));
}

function getConfigVal($const) {
	global $db;

	$data = $db->db_query("SELECT
								configuration_value
							FROM
								".TABLE_CONFIGURATION."
							WHERE
								configuration_key = '".$const."' ");

	return $data->fields['configuration_value'];
}

function getRowCheck($const) {
	$r .= '<input type="checkbox" value="1" name="'.$const.'" id="'.strtolower($const).$i.'"'.(getConfigVal($const)=='1' || getConfigVal($const)=='true'?' checked=""':'').' /><label for="'.strtolower($const).$i.'">'.constant($const.'_TITLE').'</label><input type="hidden" name="value[]" value="'.$const.'" />';
	return $r;
}

function getRowInput($const) {
	global $db;
	
	return constant($const.'_TITLE').' '.draw_selection_field($const, 'text', getConfigVal($const)).'<input type="hidden" name="value[]" value="'.$const.'" /><br />';
}

function getRowRadio($const) {
	global $db;
	
	$data = $db->db_query("SELECT
								set_function
							FROM
								".TABLE_CONFIGURATION."
							WHERE
								configuration_key = '".$const."' ");
								
	if($const == 'GLOBAL_PRODUCTS_SITE')													
		$vals = explode('|', $data->fields['set_function']);
	else
		$vals = array(0 => '0', 1 => '1');
	$r = '<span id="'.strtolower($const).'">';
	foreach($vals AS $values) { $i++;
		$r .= '<input type="radio" name="'.$const.'" id="'.strtolower($const).$i.'" value="'.$values.'"'.(getConfigVal($const) == $values ? ' checked="checked"' : '').' /> <label for="'.strtolower($const).$i.'">'.niceValue($values).'</label>';
	}
	return $r.'</span><script type="text/javascript">$(function(){$("#'.strtolower($const).'").buttonset().fadeIn();})</script>';
}

require(DIR_WS_INCLUDES.'metatag.php');
?>
</head>
<body>
<?php require(DIR_WS_INCLUDES.'header.php'); ?>
<div id="wrapper">
	<table class="outerTable" cellspacing="0" cellpadding="0">
		<tr>
			<td class="columnLeft2" width="<?php echo BOX_WIDTH; ?>" valign="top">
				<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
			</td>
			<td class="boxCenter" valign="top">
	        	<table class="table_pageHeading" border="0" width="100%" cellspacing="0" cellpadding="0">
		   			<tr>
		     			<td class="pageHeading">Globale Konfigurationen</td>
					</tr>
				</table>
	        	<table width="100%" cellpadding="6">
					<tr>
						<td>
							<p>
								<?php echo TEXT_DESC; ?>
							</p>
						</td>
					</tr>
				</table>
				<?php 
					echo draw_form('globals', 'global_config.php', 'action=save');
				?>
					<table width="100%">
						<tr>
							<td colspan="5">
								<h2>Templatespalten</h2>
							</td>
						</tr>
						<tr class="bt bb">
							<td>
								<div id="global_column">
									<?php
										echo getRowCheck('GLOBAL_COLUMN_TOP');
										echo getRowCheck('GLOBAL_COLUMN_RIGHT');
										echo getRowCheck('GLOBAL_COLUMN_BOTTOM');
										echo getRowCheck('GLOBAL_COLUMN_LEFT');
									?>
									<script type="text/javascript">$(function(){$("#global_column").buttonset().fadeIn();})</script>
								</div>
							</td>
							<td width="1" align="right">
								<input class="button" type="submit" value="<?php echo BUTTON_SAVE ?>" />
							</td>
						</tr>
					</table><br />
					<table width="100%">
						<tr>
							<td colspan="4">
								<h2>Content Seiten</h2>
							</td>
						</tr>
						<tr class="bt bb">
							<td>
								<div id="global_content">
								<?php
									echo getRowCheck('GLOBAL_CONTENT_SHOW_PDF_BUTTON');
									echo getRowCheck('GLOBAL_CONTENT_SHOW_PRINT_BUTTON');
									echo getRowCheck('GLOBAL_CONTENT_SHOW_BACK_BUTTON');
								?>
								<script type="text/javascript">$(function(){$("#global_content").buttonset().fadeIn();})</script>
								</div>
							</td>
							<td align="right">
								<input class="button" type="submit" value="<?php echo BUTTON_SAVE ?>" />
							</td>
						</tr>
					</table><br />
					<table width="100%">
						<tr>
							<td colspan="4">
								<h2>Produkt Detailsseite</h2>
							</td>
						</tr>
						<tr class="bt bb">
							<td>
								<?php echo getRowRadio('GLOBAL_PRODUCTS_SITE'); ?>
								<input type="hidden" name="value[]" value="GLOBAL_PRODUCTS_SITE" />
							
								<span id="products_tell">
								<?php echo getRowCheck('GLOBAL_PRODUCTS_TELL'); ?>
								<input type="hidden" name="value[]" value="GLOBAL_PRODUCTS_TELL" />
								<script type="text/javascript">$(function(){$("#products_tell").buttonset().fadeIn();})</script>
								</span>

								<span id="products_ask">
								<?php echo getRowCheck('GLOBAL_PRODUCTS_ASK'); ?>
								<input type="hidden" name="value[]" value="GLOBAL_PRODUCTS_ASK" />
								<script type="text/javascript">$(function(){$("#products_ask").buttonset().fadeIn();})</script>
								</span>

								<span id="products_overlay">
								<?php echo getRowCheck('GLOBAL_PRODUCTS_OVERLAY'); ?>
								<input type="hidden" name="value[]" value="GLOBAL_PRODUCTS_OVERLAY" />
								<script type="text/javascript">$(function(){$("#products_overlay").buttonset().fadeIn();})</script>
								</span>
							</td>
							<td align="right">
								<input class="button" type="submit" value="<?php echo BUTTON_SAVE ?>" />
							</td>
						</tr>
					</table><br />
					<table width="100%">
						<tr>
							<td colspan="2">
								<h2>Emailadressen/-namen</h2>
							</td>
						</tr>
						<tr class="bt bb">
							<td>
								<table width="100%">
									<tr>
										<?php
											echo '<td>'.getRowInput('GLOBAL_EMAIL_ADDRESS').'</td>';
											echo '<td>'.getRowInput('GLOBAL_EMAIL_ADDRESS_NAME').'</td>';
										?>
									</tr>
									<tr>
										<?php
											echo '<td>'.getRowInput('GLOBAL_EMAIL_REPLAY_ADDRESS');
											echo '<td>'.getRowInput('GLOBAL_EMAIL_REPLAY_ADDRESS_NAME');
										?>
									</tr>
								</table>
							</td>
							<td align="right">
								<input class="button" type="submit" value="<?php echo BUTTON_SAVE ?>" />
							</td>
						</tr>
					</table>
				</form>
		    </td>
		</tr>
	</table>
</div>
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
